package com.loan.web.pdf.controller.create;

import com.loan.common.annotation.Log;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.AjaxResult;
import com.loan.common.core.page.TableDataInfo;
import com.loan.common.enums.BusinessType;
import com.loan.common.utils.poi.ExcelUtil;
import com.loan.system.create.domain.AssistPdfSearchJhBase;
import com.loan.system.create.service.IAssistPdfSearchJhBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * JH数据Controller
 *
 * @author Sophia
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/system/jhSearch")
public class AssistPdfSearchJhBaseController extends BaseController {
    @Autowired
    private IAssistPdfSearchJhBaseService assistPdfSearchJhBaseService;

    /**
     * 查询JH数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:jhSearch:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssistPdfSearchJhBase assistPdfSearchJhBase) {
        startPage();
        List<AssistPdfSearchJhBase> list = assistPdfSearchJhBaseService.selectAssistPdfSearchJhBaseList(assistPdfSearchJhBase);
        return getDataTable(list);
    }

    /**
     * 导出JH数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:jhSearch:export')")
    @Log(title = "JH数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssistPdfSearchJhBase assistPdfSearchJhBase) {
        List<AssistPdfSearchJhBase> list = assistPdfSearchJhBaseService.selectAssistPdfSearchJhBaseList(assistPdfSearchJhBase);
        ExcelUtil<AssistPdfSearchJhBase> util = new ExcelUtil<AssistPdfSearchJhBase>(AssistPdfSearchJhBase.class);
        util.exportExcel(response, list, "JH数据数据");
    }

    /**
     * 获取JH数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:jhSearch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(assistPdfSearchJhBaseService.selectAssistPdfSearchJhBaseById(id));
    }

    /**
     * 新增JH数据
     */
    @PreAuthorize("@ss.hasPermi('system:jhSearch:add')")
    @Log(title = "JH数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssistPdfSearchJhBase assistPdfSearchJhBase) {
        return toAjax(assistPdfSearchJhBaseService.insertAssistPdfSearchJhBase(assistPdfSearchJhBase));
    }

    /**
     * 修改JH数据
     */
    @PreAuthorize("@ss.hasPermi('system:jhSearch:edit')")
    @Log(title = "JH数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssistPdfSearchJhBase assistPdfSearchJhBase) {
        return toAjax(assistPdfSearchJhBaseService.updateAssistPdfSearchJhBase(assistPdfSearchJhBase));
    }

    /**
     * 删除JH数据
     */
    @PreAuthorize("@ss.hasPermi('system:jhSearch:remove')")
    @Log(title = "JH数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(assistPdfSearchJhBaseService.deleteAssistPdfSearchJhBaseByIds(ids));
    }
}
